﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevSky.WebParts.Resourcen;

namespace DevSky.WebParts.DBConnectWP
{
    [Serializable]
    public class Lookupefinition
    {
        public string DBObjectName { get; set; }
        public string DisplayField { get; set; }
        public string KeyField { get; set; }
        public bool IsMultipleValues { get; set; }
        public bool AddEmptyEntry { get; set; }
        public string ShowListAs { get; set; }
    }

    [Serializable]
    public class CustomDataColumn
    {
        public static int index = 0;
        private int uniqueID = 0;
        private string errorMessage = string.Empty;

        public CustomDataColumn()
        {
            index++;
            uniqueID = index;
        }

        public int UniqueID
        {
            get
            {
                return uniqueID;
            }
        }

        public string Name  { get; set; }       
        public string Description { get; set; }
        public bool IsFilterable { get; set; }
        public bool IsVisible { get; set; }
        public int Position { get; set; }
        public string DisplayName { get; set; }
        public string Tooltip { get; set; }
        public bool IsDialogVisible { get; set; }
        public bool IsRequired { get; set; }
        public bool IsGroupable { get; set; }
        public bool IsUniqueColumn { get; set; }
        public string DataType { get; set; }
        public string InputFormat { get; set; }
        public Lookupefinition Lookup { get; set; }
        public string ErrorMessage 
        {
            get
            {
                if (string.IsNullOrEmpty(errorMessage))
                    return WPStrings.VAL_ErrorRequiredField;
                return errorMessage;
            }
            set
            {
                errorMessage = value;
            }
        }
        public string RegularExpression { get; set; }
        // Helper
        public string DBObjectName
        {
            get
            {
                if (Lookup != null)
                    return Lookup.DBObjectName;
                return string.Empty;
            }
        }

        public bool IsLookupColumn
        {
            get
            {
                return ((Lookup != null) 
                    && (!string.IsNullOrEmpty(Lookup.DBObjectName)) 
                    && (!string.IsNullOrEmpty(Lookup.DisplayField)) 
                    && (!string.IsNullOrEmpty(Lookup.KeyField)));
            }
        }
    }
}
